﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace AppTemplate.UI.Converters
{
    public class ProgressIndicatorVisibilityConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values == null || values.Length < 1)
            {
                return Visibility.Collapsed;
            }
            Visibility progressBarVisibility = Visibility.Collapsed;
            bool isIndeterminate = false;

            //SolidColorBrush

            if (values[0] is Visibility)
            {
                progressBarVisibility = (Visibility)values[0];
            }
            else if (values[0] is bool)
            {
                isIndeterminate = (bool)values[0];
            }

            if (values[1] is Visibility)
            {
                progressBarVisibility = (Visibility)values[1];
            }
            else if (values[1] is bool)
            {
                isIndeterminate = (bool)values[1];
            }

            if (progressBarVisibility == Visibility.Visible && isIndeterminate == false)
            {
                return Visibility.Visible;
            }
            return Visibility.Collapsed;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
